package com.ruoyi.web.controller.system;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ProjectPlan;
import com.ruoyi.system.domain.ProjectTransferDetails;
import com.ruoyi.system.service.ProjectTransferDetailsService;
import com.ruoyi.system.service.impl.ProjectPlanServiceImpl;
import com.ruoyi.system.service.impl.ProjectTransferDetailsServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目立项详情表(project_transfer_details)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/project/transfer")
public class ProjectTransferDetailsController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ProjectTransferDetailsService projectTransferDetailsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/list")
    public ProjectTransferDetails selectOne(String id) {
        return projectTransferDetailsService.selectByPrimaryKey(id);
    }


    /**
     * 查询项目立项详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/lists")
    public TableDataInfo list(ProjectTransferDetails projectTransferDetails)
    {
        startPage();
        List<ProjectTransferDetails> list = projectTransferDetailsService.selectProjectTransferDetailsList(projectTransferDetails);
        return getDataTable(list);
    }

    /**
     * 导出项目立项详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:export')")
    @Log(title = "项目立项详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(HttpServletResponse response,ProjectTransferDetails projectTransferDetails)
    {
        List<ProjectTransferDetails> list = projectTransferDetailsService.selectProjectTransferDetailsList(projectTransferDetails);
        ExcelUtil<ProjectTransferDetails> util = new ExcelUtil<ProjectTransferDetails>(ProjectTransferDetails.class);
        return util.exportExcel(response,list, "项目立项详情数据");
    }


    @PostMapping("/insert")
    public int insert(@RequestBody ProjectTransferDetails projectTransferDetails) {
        return projectTransferDetailsService.insert(projectTransferDetails);
    }

    @PostMapping("/update")
    public int update(@RequestBody ProjectTransferDetails projectTransferDetails) {
        return projectTransferDetailsService.updateByPrimaryKeySelective(projectTransferDetails);
    }

    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable String id){
        return projectTransferDetailsService.deleteByPrimaryKey(id);
    }
}